home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_emacs.idb / usr / freeware / info / viper-2.z / viper-2 (.txt)
GNU Info File  |  1998-10-27  |  39KB  |  683 lines

  1. This is Info file ../info/viper, produced by Makeinfo-1.63 from the
  2. input file viper.texi.
  3. Distribution
  4. ************
  5. Copyright (C) 1995, 1996 Free Software Foundation, Inc.
  6.    Permission is granted to make and distribute verbatim copies of this
  7. manual provided the copyright notice and this permission notice are
  8. preserved on all copies.
  9.    Permission is granted to copy and distribute modified versions of
  10. this manual under the conditions for verbatim copying, provided that
  11. the entire resulting derived work is distributed under the terms of a
  12. permission notice identical to this one.
  13.    Permission is granted to copy and distribute translations of this
  14. manual into another language, under the same conditions as for modified
  15. versions.
  16. File: viper,  Node: New Commands,  Next: Useful Packages,  Prev: Movement and Markers,  Up: Improvements over Vi
  17. New Commands
  18. ============
  19.    These commands have no Vi analogs.
  20. `C-x, C-c'
  21.      `C-x' will exit from Vi state and return to Emacs state
  22.      *temporarily*. If you hit one of these keys, Emacs will believe
  23.      that you hit that key in Emacs state. For example, if you hit `C-x'
  24.      followed by `2', then the current window will be split into 2 and
  25.      you will be in Vi state again. Except for novice users, `C-c' is
  26.      also set to temporarily escape to Emacs and execute a command from
  27.      the current major mode.  `ESC' will do the same, if you configure
  28.      ESC as Meta by setting `vip-no-multiple-ESC' to nil in `.vip'.
  29.      *Note Customization::. `C-z' in Insert state will make Emacs think
  30.      `Meta' has been hit.
  31.      Escape to Emacs to execute a single Emacs command. For instance, `\
  32.      ESC' will act like a Meta key.
  33.      `Q' is for query replace.  By default, each string to be replaced
  34.      is treated as a regular expression. You can use `(setq
  35.      vip-re-query-replace nil)' in your `.emacs' file to turn this off.
  36.      (For normal searches, `:se nomagic' will work. Note that `:se
  37.      nomagic' turns Regexps off completely, unlike Vi).
  38. `C-v'
  39.      These keys are used to visit files.  `v' will switch to a buffer
  40.      visiting file whose name can be entered in the Minibuffer. `V' is
  41.      similar, but will use a window different from the current window.
  42.      `C-v' is like `V', except that a new frame (X window) will be used
  43.      instead of a new Emacs window.
  44.      If followed by a certain character CH, it becomes an operator whose
  45.      argument is the region determined by the motion command that
  46.      follows (indicated as <move>).  Currently, CH can be one of `c',
  47.      `C', `g', `q', and `s'. For instance, `#qr' will prompt you for a
  48.      string and then prepend this string to each line in the buffer.
  49. `# c'
  50.      Change upper case characters in the region to lower case
  51.      (`downcase-region').  Emacs command `M-l' does the same for words.
  52. `# C'
  53.      Change lower case characters in the region to upper case. For
  54.      instance, `# C 3 w' will capitalize 3 words from the current point
  55.      (`upcase-region').  Emacs command `M-u' does the same for words.
  56. `# g'
  57.      Execute last keyboard macro for each line in the region
  58.      (`vip-global-execute').
  59. `# q'
  60.      Insert specified string at the beginning of each line in the region
  61.      (`vip-quote-region').
  62. `# s'
  63.      Check spelling of words in the region (`spell-region').  The
  64.      function used for spelling is determined from the variable
  65.      `vip-spell-function'.
  66.      Call last keyboard macro.
  67. `m .'
  68.      Set mark at point and push old mark off the ring
  69.      Set mark at beginning and end of buffer, respectively.
  70.      Jump to mark and pop mark off the ring. *Note Mark: (emacs)Mark,
  71.      for more info.
  72. `] register'
  73.      View contents of register
  74. `[ textmarker'
  75.      View filename and position of textmarker
  76. `@register'
  77.      Begin/end keyboard macro. @register has a different meaning when
  78.      used after a `@#'. *Note Macros and Registers::, for details
  79.      Go to end of heading.
  80. `g <*movement command*>'
  81.      Search buffer for text delimited by movement command. The canonical
  82.      example is `gw' to search for the word under the cursor.  *Note
  83.      Improved Search::, for details.
  84.      Meta key when in Vi state.*Note Vi State::, for an explanation.
  85. `C-g and C-]'
  86.      Quit and Abort Recursive edit. These may be necessary on occasion.
  87.      *Note Vi State::, for a reason.
  88. `C-c g'
  89.      Hitting `C-c' followed by `g' will display the information on the
  90.      current buffer. This is the same as hitting  `C-g' in Vi, but, as
  91.      explained above, `C-g' is needed for other purposes in Emacs.
  92. `C-c /'
  93.      Without a prefix argument, this command toggles
  94.      case-sensitive/case-insensitive search modes and plain
  95.      vanilla/regular expression search. With the prefix argument 1,
  96.      i.e., `1 C-c /', this toggles case-sensitivity; with the prefix
  97.      argument 2, toggles plain vanilla search and search using regular
  98.      expressions. *Note Viper Specials::, for alternative ways to invoke
  99.      this function.
  100. `M-p and M-n'
  101.      In the Minibuffer, these commands navigate through the minibuffer
  102.      histories, such as the history of search strings, Ex commands, etc.
  103. `C-c M-p and C-c M-n'
  104.      In Insert or Replace state, these commands let  the user peruse
  105.      the history of insertion strings used in previous insert or replace
  106.      commands. Try to hit `C-c M-p' or `C-c M-n' repeatedly and see what
  107.      happens. *Note Viper Specials::, for more.
  108.      In Vi state, these commands let the user peruse the history of
  109.      Vi-style destructive commands, such as `dw', `J', `a', etc.  By
  110.      repeatedly typing `C-c M-p' or `C-c M-n' you will cycle Viper
  111.      through the recent history of Vi commands, displaying the commands
  112.      one by one. Once an appropriate command is found, it can be
  113.      executed by typing ``.''.
  114.      Since typing `C-c M-p' is tedious, it is more convenient to bind an
  115.      appropriate function to a function key on the keyboard and use
  116.      that key.  *Note Viper Specials::, for details.
  117. `Ex commands'
  118.      The commands `:args', `:next', `:pre' behave differently. `:pwd'
  119.      exists to get current directory.  The commands `:b' and `:B'
  120.      switch buffers around. *Note File and Buffer Handling::, for
  121.      details.  There are also the new commands `:RelatedFile' and
  122.      `PreviousRelatedFile' (which abbreviate to `R' and `P',
  123.      respectively. *Note Viper Specials::, for details.
  124.    Apart from the new commands, many old commands have been enhanced.
  125. Most notably, Vi style macros are much more powerful in Viper than in
  126. Vi. *Note Vi Macros::, for details.
  127. File: viper,  Node: Useful Packages,  Prev: New Commands,  Up: Improvements over Vi
  128. Useful Packages
  129. ===============
  130.    Some Emacs packages are mentioned here as an aid to the new Viper
  131. user, to indicate what Viper is capable of.  A vast number comes with
  132. the standard Emacs distribution, and many more exist on the net and on
  133. the archives.
  134.    This manual also mentions some Emacs features a new user should know
  135. about. The details of these are found in the GNU Emacs Manual.
  136.    The features first. For details, look up the Emacs Manual.
  137. `Make'
  138.      Makes and Compiles can be done from the editor. Error messages
  139.      will be parsed and you can move to the error lines.
  140. `Shell'
  141.      You can talk to Shells from inside the editor. Your entire shell
  142.      session can be treated as a file.
  143. `Mail'
  144.      Mail can be read from and sent within the editor. Several
  145.      sophisticated packages exist.
  146. `Language Sensitive Editing'
  147.      Editing modes are written for most computer  languages in
  148.      existence. By controlling indentation, they catch punctuation
  149.      errors.
  150.    The packages, below, represents a drop in the sea of special-purpose
  151. packages that come with standard distribution of Emacs 19.
  152. `Transparent FTP'
  153.      `ange-ftp.el' can ftp from the editor to files on other machines
  154.      transparent to the user.
  155. `RCS Interfaces'
  156.      `vc.el' for doing RCS commands from inside the editor
  157. `Directory Editor'
  158.      `dired.el' for editing contents of directories and for navigating
  159.      in the file system.
  160. `Syntactic Highlighting'
  161.      `hilit19.el' and `font-lock.el' for automatic highlighting various
  162.      parts of a buffer using different fonts and colors.
  163. `Saving Emacs Configuration'
  164.      `desktop.el' for saving/restoring configuration on Emacs
  165.      exit/startup.
  166. `Spell Checker'
  167.      `ispell.el' for spell checking the buffer, words, regions, etc.
  168. `File and Buffer Comparison'
  169.      `ediff.el' for finding differences between files and for applying
  170.      patches.
  171. Emacs Lisp archives exist on `archive.cis.ohio-state.edu' and
  172. `wuarchive.wustl.edu'
  173. File: viper,  Node: Customization,  Next: Commands,  Prev: Improvements over Vi,  Up: Top
  174. Customization
  175. *************
  176.    Customization can be done in 2 ways.
  177.    * Elisp code in a `.vip' file in your home directory. Viper loads
  178.      `.vip' just before it does the binding for mode hooks. This is the
  179.      recommended method.
  180.    * Elisp code in your `.emacs' file before and after the `(require
  181.      'viper)' line. This method is not recommended, unless you are know
  182.      what you are doing.
  183. Emacs customization is done in Emacs Lisp. For the common cases,
  184. examples are provided that you can use directly.
  185. * Menu:
  186. * Rudimentary Changes::          Simple constant definitions.
  187. * Keybindings::                  Enabling Emacs Keys, Rebinding keys, etc.
  188. * Packages that Change Keymaps:: How to deal with such beasts.
  189. * Viper Specials::               Special Viper commands.
  190. * Vi Macros::                    How to do Vi style macros.
  191. File: viper,  Node: Rudimentary Changes,  Next: Keybindings,  Prev: Customization,  Up: Customization
  192. Rudimentary Changes
  193. ===================
  194.    An easy way to customize Viper is to change the values of constants
  195. used in Viper.  Here is the list of the constants used in Viper and
  196. their default values. The corresponding :se command is also indicated.
  197. (The symbols `t' and `nil' represent "true" and "false" in Lisp).
  198.    Viper supports both the abbreviated Vi variable names and their full
  199. names. Variable completion is done on full names only. `TAB' and `SPC'
  200. complete variable names. Typing `=' will complete the name and then
  201. will prompt for a value, if applicable. For instance, `:se auSPC' will
  202. complete the command to `:set autoindent'; `:se taSPC' will complete
  203. the command and prompt further like this: `:set tabstop = '.  However,
  204. typing `:se tsSPC' will produce a "No match" message because `ts' is an
  205. abbreviation for `tabstop' and Viper supports completion on full names
  206. only. However, you can still hit `RET' or `=', which will complete the
  207. command like this: `:set ts = ' and Viper will be waiting for you to
  208. type a value for the tabstop variable.  To get the full list of Vi
  209. variables, type `:se SPC TAB'.
  210. `vip-auto-indent nil'
  211. `:se ai (:se autoindent)'
  212. `:se gai (:se global-autoindent)'
  213.      If `t', enable auto indentation.  by `RET', `o' or `O' command.
  214.      `vip-auto-indent' is a local variable. To change the value
  215.      globally, use `setq-default'. It may be useful for certain major
  216.      modes to have their own values of `vip-auto-indent'. This can be
  217.      achieved by using `setq' to change the local value of this
  218.      variable in the hooks to the appropriate major modes.
  219.      `:se ai' changes the value of `vip-auto-indent' in the current
  220.      buffer only; `:se gai' does the same globally.
  221. `vip-electric-mode t'
  222.      If `t', auto-indentation becomes electric, which means that `RET',
  223.      `O', and `o' indent cursor according to the current major mode. In
  224.      the future, this variable may control additional electric features.
  225.      This is a local variable: `setq' changes the value of this variable
  226.      in the current buffer only. Use `setq-default' to change the value
  227.      in all buffers.
  228. `vip-case-fold-search nil'
  229. `:se ic (:se ignorecase)'
  230.      If `t', search ignores cases.  This can also be toggled by quickly
  231.      hitting `/' twice.
  232. `vip-re-search nil'
  233. `:se magic'
  234.      If `t' then search is reg-exp search, if `nil' then vanilla search.
  235.      This behavior can also be toggled by quickly hitting `/' trice.
  236. `buffer-read-only'
  237. `:se ro (:se readonly)'
  238.      Set current buffer to read only. To change globally put
  239.      `(setq-default buffer-read-only t)' in your `.emacs' file.
  240. `blink-matching-paren t'
  241. `:se sm (:se showmatch)'
  242.      Show matching parens by blinking cursor.
  243. `tab-width t (default setting via `setq-default')'
  244. `:se ts=value (:se tabstop=value)'
  245. `:se gts=value (:se global-tabstop=value)'
  246.      `tab-width' is a local variable that controls the width of the tab
  247.      stops.  To change the value globally, use `setq-default'; for
  248.      local settings, use `setq'.
  249.      The command `:se ts' sets the tab width in the current buffer
  250.      only; it has no effect on other buffers.
  251.      The command `:se gts' sets tab width globally, for all buffers
  252.      where the tab is not yet set locally, including the new buffers.
  253.      Note that typing `TAB' normally doesn't insert the tab, since this
  254.      key is usually bound to a text-formatting function,
  255.      `indent-for-tab-command' (which facilitates programming and
  256.      document writing). Instead, the tab is inserted via the command
  257.      `vip-insert-tab', which is bound to `S-tab' (shift + tab).
  258.      On some non-windowing terminals, Shift doesn't modify the `TAB'
  259.      key, so `S-tab' behaves as if it were `TAB'. In such a case, you
  260.      will have to bind `vip-insert-tab' to some other convenient key.
  261. `vip-shift-width 8'
  262. `:se sw=value  (:se shiftwidth=value)'
  263.      The number of columns shifted by `>' and `<' commands.
  264. `vip-search-wrap-around t'
  265. `:se ws (:se wrapscan)'
  266.      If `t', search wraps around the end/beginning of buffer.
  267. `vip-tags-file-name "TAGS"'
  268.      The name of the file used as the tag table.
  269. `vip-re-query-replace nil'
  270.      If `t', use reg-exp replace in query replace.
  271. `vip-want-ctl-h-help nil'
  272.      If `t', `C-h' is bound to `help-command'; if `nil', it is bound to
  273.      `delete-backward-char'.
  274. `vip-vi-style-in-minibuffer t'
  275.      If `t', Viper provides a high degree of compatibility with Vi
  276.      insert mode when you type text in the Minibuffer; if `nil', typing
  277.      in the Minibuffer feels like plain Emacs.
  278. `vip-no-multiple-ESC t'
  279.      If you set this to `nil', you can use `ESC' as Meta in Vi state.
  280.      Normally, this is not necessary, since graphical displays have
  281.      separate Meta keys (usually on each side of the space bar). On a
  282.      dumb terminal, Viper sets this variable to `twice', which is
  283.      almost like `nil', except that double `ESC' beeps. This, too, lets
  284.      ESC to be used as a Meta.
  285. `vip-keysequence-delay 140'
  286.      Escape sequences separated by this much delay are interpreted as
  287.      command, ignoring the special meaning of ESC in VI. The default is
  288.      suitable for most terminals. However, if your terminal is
  289.      extremely slow, you might want to increase this slightly. You will
  290.      know if your terminal is slow if the ESC key sequences emitted by
  291.      the arrow keys are interpreted as separately typed characters (and
  292.      thus the arrow keys won't work).  Making this value too large will
  293.      slow you down, so exercise restraint.
  294. `vip-ex-style-motion t'
  295.      Set this to `nil', if you want `l,h' to cross lines, etc. *Note
  296.      Movement and Markers::, for more info.
  297. `vip-ex-style-editing-in-insert t'
  298.      Set this to to `nil', if you want `ESC' to not move back and `C-h'
  299.      to not stop at the beginning of a line in Insert state.
  300. `vip-always t'
  301.      Leave it to Viper to decide when a buffer must be brought up in Vi
  302.      state, Insert state, or Emacs state. This heuristics works well in
  303.      virtually all cases.  This option must be set before Viper is
  304.      loaded or in the `.vip' file.
  305. `vip-custom-file-name "~/.vip"'
  306.      Change this if you want. Must be set in `.emacs' (not `.vip'!)
  307.      before Viper is loaded. Note that you have to set it as a string
  308.      inside double quotes.
  309. `vip-spell-function 'ispell-region'
  310.      Function used by the command `#c<move>' to spell.
  311. `ex-nontrivial-find-file-function'
  312.      The value of this variable is the function used to find all files
  313.      that match a wildcard. This is usually done when the user types
  314.      `:e' and specifies a wildcard in the file name (or if the file
  315.      name contains unusual symbols (e.g., a space). Viper provides two
  316.      functions for this: one for Unix-like systems
  317.      (`vip-ex-nontrivial-find-file-unix') and one for DOS, W95, and NT
  318.      (`vip-ex-nontrivial-find-file-ms'). If the default function
  319.      doesn't quite do what you expect or if you prefer to use "fancy"
  320.      shells, you may have to write your own version of this function
  321.      and make it into the value of `ex-nontrivial-find-file-function'.
  322.      Use `vip-ex-nontrivial-find-file-unix' and
  323.      `vip-ex-nontrivial-find-file-ms' as examples.
  324. `ex-cycle-other-window t'
  325.      If `t', `:n' and `:b' will cycle through files in another window,
  326.      if one exists.
  327. `ex-cycle-through-non-files nil'
  328.      `:n' does not normally cycle through buffers. Set this to get
  329.      buffers also.
  330. `vip-automatic-iso-accents nil'
  331.      If `t', ISO accents will be turned on in insert/replace Viper
  332.      states and turned off in Vi state. This is useful for editing text
  333.      in European languages. This variable is buffer-local. If used, it
  334.      should be set in the hooks to the appropriate major modes (usually
  335.      setting it in `text-mode-hook' is enough).
  336. `vip-want-emacs-keys-in-insert'
  337.      This is set to `nil' for user levels 1 and 2 and to `t' for user
  338.      levels 3 and 4. Users who specify level 5 are allowed to set this
  339.      variable as they please (the default for this level is `t'). If
  340.      set to `nil', complete Vi compatibility is provided in Insert
  341.      state. This is really not recommended, as this precludes you from
  342.      using language-specific features provided by the major modes.
  343. `vip-want-emacs-keys-in-vi'
  344.      This is set to `nil' for user level 1 and to `t' for user levels
  345.      2-4.  At level 5, users are allowed to set this variable as they
  346.      please (the default for this level is `t').  If set to `nil',
  347.      complete Vi compatibility is provided in Vi command state. Setting
  348.      this to `nil' is really a bad idea, unless you are a novice, as
  349.      this precludes the use of language-specific features provided by
  350.      the major modes.
  351. `vip-keep-point-on-repeat t'
  352.      If `t', point is not moved when the user repeats the previous
  353.      command by typing `.'  This is very useful for doing repeated
  354.      changes with the `.' key.
  355. `vip-repeat-from-history-key 'f12'
  356.      Prefix key used to invoke the macros `f12 1' and `f12 2' that
  357.      repeat the second-last and the third-last destructive command.
  358.      Both these macros are bound (as Viper macros) to
  359.      `vip-repeat-from-history', which checks the second key by which it
  360.      is invoked to see which of the previous commands to invoke. Viper
  361.      binds `f12 1' and `f12 2' only, but the user can bind more in
  362.      `~/.vip'. *Note Vi Macros::, for how to do this.
  363. `vip-keep-point-on-undo nil'
  364.      If `t', Viper tries to not move point when undoing commands.
  365.      Instead, it will briefly move the cursor to the place where change
  366.      has taken place. However, if the undone piece of text is not seen
  367.      in window, then point will be moved to the place where the change
  368.      took place.  Set it to `t' and see if you like it better.
  369. `vip-delete-backwards-in-replace nil'
  370.      If `t', DEL key will delete characters while moving the cursor
  371.      backwards.  If `nil', the cursor will move backwards without
  372.      deleting anything.
  373. `vip-replace-overlay-face 'vip-replace-overlay-face'
  374.      On a graphical display, Viper highlights replacement regions
  375.      instead of putting a `$' at the end. This variable controls the so
  376.      called "face" used to highlight the region.
  377.      By default, `vip-replace-overlay-face' underlines the replacement
  378.      on monochrome displays and highlights it with color on  color
  379.      displays.  If you know something about Emacs faces and don't like
  380.      how Viper highlights replacement regions, you can change this
  381.      variable to specify a new face name. (Emacs faces are described in
  382.      the Emacs Lisp reference.) On a color display, the following
  383.      customization method is usually most effective:
  384.           (set-face-foreground vip-replace-overlay-face "DarkSlateBlue")
  385.           (set-face-background vip-replace-overlay-face "yellow")
  386.      For a complete list of colors available to you, evaluate the
  387.      expression `(x-defined-colors)'. (Type it in the buffer `*scratch*'
  388.      and then hit the `C-j' key.
  389. `vip-replace-overlay-cursor-color  "Red"'
  390.      Cursor color when it is inside the replacement region.  This has
  391.      effect only on color displays and only when Emacs runs as an X
  392.      application.
  393. `vip-replace-region-end-delimiter "$"'
  394.      A string used to mark the end of replacement regions.  It is used
  395.      only with TTYs or if `vip-use-replace-region-delimiters' is
  396.      non-nil.
  397. `vip-replace-region-start-delimiter  ""'
  398.      A string used to mark the beginning of replacement regions.  It is
  399.      used only with TTYs or if `vip-use-replace-region-delimiters' is
  400.      non-nil.
  401. `vip-use-replace-region-delimiters'
  402.      If non-nil, Viper will always use
  403.      `vip-replace-region-end-delimiter' and
  404.      `vip-replace-region-start-delimiter' to delimit replacement
  405.      regions, even on color displays (where this is unnecessary). By
  406.      default, this variable is non-nil only on TTYs or monochrome
  407.      displays.
  408. `vip-toggle-key "\C-z"'
  409.      Specifies the key used to switch from Emacs to Vi and back.  Must
  410.      be set in `.vip' or prior to loading Viper. This variable can't be
  411.      changed interactively after Viper is loaded.
  412. `vip-ESC-key "\e"'
  413.      Specifies the key used to escape from Insert/Replace states to Vi.
  414.      Must be set in `.vip' or prior to loading Viper. This variable
  415.      cannot be changed interactively after Viper is loaded.
  416. `vip-buffer-search-char nil'
  417.      Key used for buffer search. *Note Viper Specials::, for details.
  418. `vip-surrounding-word-function 'vip-surrounding-word'
  419.      The value of this variable is a function name that is used to
  420.      determine what constitutes a word clicked upon by the mouse. This
  421.      is used by mouse search and insert.
  422. `vip-search-face 'vip-search-face'
  423.      Variable that controls how search patterns are highlighted when
  424.      they are found.
  425. `vip-vi-state-hook nil'
  426.      List of parameterless functions to be run just after entering the
  427.      Vi command state.
  428. `vip-insert-state-hook nil'
  429.      Same for Insert state. This hook is also run after entering
  430.      Replace state.
  431. `vip-replace-state-hook  nil'
  432.      List of (parameterless) functions called just after entering
  433.      Replace state (and after all `vip-insert-state-hook').
  434. `vip-emacs-state-hook nil'
  435.      List of (parameterless) functions called just after switching from
  436.      Vi state to Emacs state.
  437. `vip-load-hook nil'
  438.      List of (parameterless) functions called just after loading Viper.
  439.      This is the last chance to do customization before Viper is up and
  440.      running.
  441. You can reset some of these constants in Viper with the Ex command
  442. `:set' (when so indicated in the table).  Or you can include a line
  443. like this in your `.vip' file:
  444.      (setq vip-case-fold-search t)
  445. File: viper,  Node: Keybindings,  Next: Packages that Change Keymaps,  Prev: Rudimentary Changes,  Up: Customization
  446. Keybindings
  447. ===========
  448.    Viper lets you define hot keys, i.e., you can associate keyboard keys
  449. such as F1, Help, PgDn, etc., with Emacs Lisp functions (that may
  450. already exist or that you will write). Each key has a "preferred form"
  451. in Emacs. For instance, the Up key's preferred form is [up], the Help
  452. key's preferred form is [help], and the Undo key has the preferred form
  453. [f14].  You can find out the preferred form of a key by typing `M-x
  454. describe-key-briefly' and then typing the key you want to know about.
  455.    Under X Windows, every keyboard key emits its preferred form, so you
  456. can just type
  457.      (global-set-key [f11] 'calendar)                        ; L1, Stop
  458.      (global-set-key [f14] 'undo)                            ; L4, Undo
  459. to bind L1 so it will invoke the Emacs Calendar and to bind L4 so it
  460. will undo changes.  However, on a dumb terminal or in an Xterm window,
  461. even the standard arrow keys may not emit the right signals for Emacs
  462. to understand. To let Emacs know about those keys, you will have to
  463. find out which key sequences they emit by typing `C-q' and then the key
  464. (you should switch to Emacs state first). Then you can bind those
  465. sequences to their preferred forms using `function-key-map' as follows:
  466.      (cond ((string= (getenv "TERM") "xterm")
  467.             (define-key function-key-map "\e[192z" [f11])    ; L1
  468.             (define-key function-key-map "\e[195z" [f14])    ; L4, Undo
  469.    The above illustrates how to do this for Xterm. On VT100, you would
  470. have to replace "xterm" with "vt100" and also change the key sequences
  471. (the same key may emit different sequences on different types of
  472. terminals).
  473.    The above keys are global, so they are overwritten by the local maps
  474. defined by the major modes and by Viper itself. Therefore, if you wish
  475. to change a binding set by a major mode or by Viper, read this.
  476.    Viper users who wish to specify their own key bindings should be
  477. concerned only with the following three keymaps:
  478. `vip-vi-global-user-map' for Vi state commands,
  479. `vip-insert-global-user-map' for Insert state commands, and
  480. `vip-emacs-global-user-map' for Emacs state commands (note: customized
  481. bindings for Emacs state made to `vip-emacs-global-user-map' are *not*
  482. inherited by Insert state).
  483.    For more information on Viper keymaps, see the header of the file
  484. `viper.el'.  If you wish to change a Viper binding, you can use the
  485. `define-key' command, to modify `vip-vi-global-user-map',
  486. `vip-insert-global-user-map', and `vip-emacs-global-user-map', as
  487. explained below. Each of these key maps affects the corresponding Viper
  488. state.  The keymap `vip-vi-global-user-map' also affects Viper's
  489. Replace state.
  490. If you want to bind a key, say `C-v', to the function that scrolls page
  491. down and to make `0' display information on the current buffer, putting
  492. this in `.vip' will do the trick in Vi state:
  493.      (define-key vip-vi-global-user-map "\C-v" 'scroll-down)
  494. To set a key globally,
  495.      (define-key vip-emacs-global-user-map "\C-c m" 'smail)
  496.      (define-key vip-vi-global-user-map "0" 'vip-info-on-file)
  497. Note, however, that this binding may be overwritten by other keymaps,
  498. since the global keymap has the lowest priority.  To make sure that
  499. nothing will override a binding in Emacs state, you can write this:
  500.      (define-key vip-emacs-global-user-map "\C-c m" 'smail)
  501. To customize the binding for `C-h' in Insert state:
  502.      (define-key vip-insert-global-user-map "\C-h" 'my-del-backwards-function)
  503. Each Emacs command key calls some lisp function. If you have enabled the
  504. Help, (*Note Rudimentary Changes::) `C-h k' will show you the function
  505. for each specific key; `C-h b' will show all bindings, and `C-h m' will
  506. provide information on the major mode in effect. If Help is not
  507. enabled, you can still get help in Vi state by prefixing the above
  508. commands with `\', e.g., `\ C-h k' (or you can use the Help menu in the
  509. menu bar, if Emacs runs under X Windows).
  510.    Viper users can also change bindings on a per major mode basis.  As
  511. with global bindings, this can be done separately for each of the three
  512. main Viper states.  To this end, Viper provides the function
  513. `vip-modify-major-mode'.
  514.    To modify keys in Emacs state for `my-favorite-major-mode', the user
  515. needs to create a sparse keymap, say, `my-fancy-map', bind whatever
  516. keys necessary in that keymap, and put
  517.      (vip-modify-major-mode 'dired-mode 'emacs-state my-fancy-map)
  518. in `~/.vip'. To do the same in Vi and Insert states, one should use
  519. `vi-state' and `insert-state'. Changes in Insert state are also in
  520. effect in Replace state.  For instance, suppose that the user wants to
  521. use `dd' in Vi state under Dired mode to delete files, `u' to unmark
  522. files, etc. The following code in `~/.vip' will then do the job:
  523.      (setq my-dired-modifier-map (make-sparse-keymap))
  524.      (define-key my-dired-modifier-map "dd" 'dired-flag-file-deletion)
  525.      (define-key my-dired-modifier-map "u" 'dired-unmark)
  526.      (vip-modify-major-mode 'dired-mode 'vi-state my-dired-modifier-map)
  527.    A Vi purist may want to modify Emacs state under Dired mode so that
  528. `k', `l', etc., will move around in directory buffers, as in Vi.
  529. Although this is not recommended, as these keys are bound to useful
  530. Dired functions, the trick can be accomplished via the following code:
  531.      (setq my-dired-vi-purist-map (make-sparse-keymap))
  532.      (define-key my-dired-vi-purist-map "k" 'vip-previous-line)
  533.      (define-key my-dired-vi-purist-map "l" 'vip-forward-char)
  534.      (vip-modify-major-mode 'dired-mode 'emacs-state my-dired-vi-purist-map)
  535.    Similar effect can be achieved by defining Vi keyboard macros using
  536. the Ex commands `:map' and `:map!'. The difference is that multi-key Vi
  537. macros do not override the keys they are bound to, unless these keys are
  538. typed in quick succession. So, with macros, one can use the normal keys
  539. alongside with the macros. If per-mode modifications are needed, the
  540. user can try both ways and see which one is more convenient.  *Note Vi
  541. Macros::, for details.
  542.    Note: in major modes that come up in *Emacs state* by default, the
  543. aforesaid modifications may not take place immediately (but only after
  544. the buffer switches to some other Viper state and then back to Emacs
  545. state).  To avoid this, one should add `vip-change-state-to-emacs' to an
  546. appropriate hook of that major mode. (Check the function
  547. `vip-set-hooks' in `viper.el' for examples.)  However, if you have set
  548. `vip-always' to `t', chances are that you won't need to perform the
  549. above procedure, because Viper will take care of most useful defaults.
  550.    Finally, Viper has a facility that lets the user define per-buffer
  551. bindings, i.e., bindings that are in effect in some specific buffers
  552. only. Unlike per-mode bindings described above, per-buffer bindings can
  553. be defined based on considerations other than the major mode.  This is
  554. done via the function `vip-add-local-keys', which lets one specify
  555. bindings that should be in effect in the current buffer only and for a
  556. specific Viper state. For instance,
  557.      (vip-add-local-keys 'vi-state '(("ZZ" . TeX-command-master)
  558.                                      ("ZQ" . vip-save-kill-buffer)))
  559. redefines `ZZ' to invoke `TeX-command-master' in `vi-state' and `ZQ' to
  560. save-then-kill the current buffer. These bindings take effect only in
  561. the buffer where this command is executed. The typical use of this
  562. function is to execute the above expression from within a function that
  563. is included in a hook to some major mode. For instance, the above
  564. expression could be called from a function, `my-tex-init', which may be
  565. added to `tex-mode-hook' as follows:
  566.      (add-hook 'tex-mode-hook 'my-tex-init)
  567. When TeX mode starts, the hook is executed and the above Lisp
  568. expression is evaluated. Then, the bindings for `ZZ' and `ZQ' are
  569. changed in Vi command mode for all buffers in TeX mode.
  570.    Another useful application is to bind `ZZ' to `send-mail' in the
  571. Mail mode buffers (the specifics of this depend on which mail package
  572. you are using, `rmail', `mh-e', `vm', etc.  For instance, here is how
  573. to do this for `mh-e', the Emacs interface to MH:
  574.      (defun mh-add-vi-keys ()
  575.        "Set up ZZ for MH-e and XMH."
  576.        (vip-add-local-keys 'vi-state '(("ZZ" . mh-send-letter))))
  577.      (add-hook 'mh-letter-mode-hook 'mh-add-vi-keys)
  578.    You can also use `vip-add-local-keys' to set per buffer bindings in
  579. Insert state and Emacs state by passing as a parameter the symbols
  580. `'insert-state' and `'emacs-state', respectively.  As with global
  581. bindings, customized local bindings done to Emacs state are not
  582. inherited by Insert state.
  583.    On rare occasions, local keys may be added by mistake. Usually this
  584. is done indirectly, by invoking a major mode that adds local keys (e.g.,
  585. `shell-mode' redefines `RET'). In such a case, exiting the wrong major
  586. mode won't rid you from unwanted local keys, since these keys are local
  587. to Viper state and the current buffer, not to the major mode.  In such
  588. situations, the remedy is to type `M-x vip-zap-local-keys'.
  589.    So much about Viper-specific bindings.  *Note Customization:
  590. (emacs)Customization, and the Emacs quick reference card for the
  591. general info on key bindings in Emacs.
  592. File: viper,  Node: Packages that Change Keymaps,  Next: Viper Specials,  Prev: Keybindings,  Up: Customization
  593. Packages that Change Keymaps
  594. ----------------------------
  595.    Viper is designed to coexist with all major and minor modes of
  596. Emacs. This means that bindings set by those modes are generally
  597. available with Viper (unless you explicitly prohibit them by setting
  598. `vip-want-emacs-keys-in-vi' and `vip-want-emacs-keys-in-insert' to
  599. `nil').  If `vip-always' is set to `t', Viper will try to bring each
  600. buffer in the a Viper state that is most appropriate for that buffer.
  601. Usually, this would be the Vi state, but sometimes it could be the
  602. Insert state or the Emacs state.
  603.    Some major mode bindings will necessarily be overwritten by Viper.
  604. Indeed, in Vi state, most of the 1-character keys are used for Vi-style
  605. editing.  This usually causes no problems because most packages
  606. designed for editing files typically do not bind such keys. Instead,
  607. they use key sequences that start with `C-x' and `C-c'. This is why it
  608. was so important for us to free up `C-x' and `C-c'.  It is common for
  609. language-specific major modes to bind `TAB' and `LFD' (the line feed)
  610. keys to various formatting functions. This is extremely useful, but may
  611. require some getting used to for a Vi user. If you decide that this
  612. feature is not for you, you can re-bind these keys as explained earlier
  613. (*Note Customization::).
  614.    Binding for `TAB' is one of the most unusual aspects of Viper for
  615. many novice users.  In Emacs, `TAB' is used to format text and
  616. programs, and is extremely useful. For instance, hitting `TAB' causes
  617. the current line to be re-indented in accordance with the context.  In
  618. programming, this is very important, since improper automatic
  619. indentation would immediately alert the programmer to a possible error.
  620. For instance, if a `)' or a `"' is missing somewhere above the current
  621. line, `TAB' is likely to mis-indent the line.
  622.    For this reason, Viper doesn't change the standard Emacs binding of
  623. `TAB', thereby sacrificing Vi compatibility (except for users at level
  624. 1). Instead, in Viper, the key `S-tab' (shift+ tab) is chosen to
  625. emulate Vi's `TAB'.
  626.    We should note that on some non-windowing terminals, Shift doesn't
  627. modify the `TAB' key, so `S-tab' behaves as if it were `TAB'. In such a
  628. case, you will have to bind `vip-insert-tab' to some other convenient
  629.    Some packages, notably Dired, Gnus, Info, etc., attach special
  630. meaning to common keys like `SPC', `x', `d', `v', and others. This
  631. means that Vi command state is inappropriate for working with these
  632. packages. Fortunately, these modes operate on read-only buffers and are
  633. designed not for editing files, but for special-purpose browsing,
  634. reading news, mail, etc., and Vi commands are meaningless in these
  635. situations. For this reason, Viper doesn't force Vi state on such major
  636. modes.  Rather, it brings them in Emacs state. You can switch to Vi
  637. state by typing `C-z' if, for instance, you want to do Vi-style search
  638. in a buffer (although, usually, incremental search, which is bound to
  639. `C-s', is sufficient in these situations). But you should then switch
  640. back to Emacs state if you plan to continue using these major modes
  641. productively. You can also switch to Vi temporarily, to execute one
  642. 1-character command. This is done by typing `M-C-z' (or `ESC C-z').
  643. This facility cannot execute several complex Vi commands, such as `dw',
  644. `de', etc.
  645.    It is also possible to harness some major modes, even though they
  646. may bind common keys to specialized commands. Harnessing can make sense
  647. for modes that bind only a small number of common keys.  For instance,
  648. if `vip-always' is set to `t' in your `~/.vip' file, Viper will harness
  649. the Shell mode by changing the bindings for `C-m' and `C-d' using
  650. `vip-add-local-keys' described in section on customization (*Note
  651. Customization::). In general, there is no single recipe for harnessing
  652. modes. It can be as simple as adding the function `viper-mode' to a
  653. hook associated with the mode, or it can be more complex, as in the
  654. case of Shell mode and Emerge. Take a look at `vip-set-hooks' function
  655. for some examples.
  656.    Conversely, it may be the case that most of the major modes harnessed
  657. by `vip-set-hooks' function fit your working style, except one or two
  658. cases. In this case, you may still be able to set `vip-always' to `t'
  659. and then remove a hook that forces Vi command state. For instance, to
  660. unharness `lisp-interaction-mode', you can put the following line in
  661. your `.emacs' (not `.vip'!) file after `(require 'viper)':
  662.      (remove-hook 'lisp-interaction-mode-hook 'viper-mode)
  663.    In some rare cases, some minor modes may override certain essential
  664. bindings in Vi command state.  This is not really catastrophic because
  665. this may happen only in the beginning, when the minor mode kicks in.
  666. Typing `M-x viper-mode' will correct the situation.  Viper knows about
  667. several such minor modes and takes care of them, so that the above trick
  668. is usually not necessary.  If you find that some minor mode, e.g.,
  669. `nasty-mode.el' interferes with Viper, putting the following in `.vip'
  670. should fix the problem:
  671.      (vip-harness-minor-mode "nasty-mode")
  672. The argument to `vip-harness-minor-mode' is the name of the file for the
  673. offending minor mode with the suffixes `.el' and `.elc' removed.
  674.    It may be tricky, however, to find out which minor mode is at fault.
  675. The only guidance here is to look into the file that defines the minor
  676. mode you are suspecting, say `nasty-mode.el', and see if it has a
  677. variable called `nasty-mode-map'. Then check if there is a statement of
  678. the form
  679.      (define-key nasty-mode-map key function)
  680. that binds the misbehaving keys. If so, use the above line to harness
  681. `nasty-mode'. If your suspicion is wrong, no harm is done if you
  682. harness a minor mode that doesn't need to be harnessed.
  683.